package com.roc.web.action.announce;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.roc.page.BaseAction;
import com.roc.pojo.Announcement;
import com.roc.service.IAnnounceService;
import com.roc.service.IPagenitionService;
import com.roc.service.ServiceException;
import com.roc.util.Constance;

@Component
@Scope("prototype")
@Namespace("/iannounce")
public class InitAccnounceAction extends BaseAction{
	private Logger logger=LogManager.getLogger(InitAccnounceAction.class);
	
	 //private Announcement announce;
	 
	
	 @Autowired 
	 IAnnounceService announceService;

	 
	 @Action(value = "initAnnoce", results = { @Result(name = "success", location = "/pages/announce/announce.jsp")
	    })
	 public String initAnnoce(){
		 try {
				List<Announcement> announceList=announceService.queryNewAnnouncement();
				List<Announcement> list=new ArrayList<Announcement>();
				if(announceList.size()>0&&announceList!=null){
					for(int i=0;i<announceList.size();i++){
						Announcement announce = announceList.get(i);
						announce.setContent(announce.getContent().replaceAll(" ","&nbsp;"));
						announce.setContent(announce.getContent().replaceAll("\r\n","<br>"));
						list.add(announce);
					}
				}
				
				getRequest().setAttribute("list", list);
				/*if(announce!=null&&!Constance.Null2EmptyTrim(announce.getContentce()).equals("")){
					announce.setContentce(announce.getContentce().replaceAll(" ","&nbsp;"));
					announce.setContentce(announce.getContentce().replaceAll("\r\n","<br>"));
             
				}*/
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				 logger.error(e.getMessage(),e);
				 addActionError(e.getMessage());
			}
			return SUCCESS;
	 }


	
	 
	 
}
